﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;

namespace WCF_LIBRARY_ATM
{
   
    public class Service1 : IService1
    {

        
        public int dangnhap(string id, string matkhau)
        {
            string sql = "select * from KHACHHANG where ID ='"+id+"'";
            DataTable dt = DatabaseConnect.ExecuteQuery(sql);       

            try
            {
                if (matkhau == dt.Rows[0]["MATKHAU"].ToString())
                {                
                  
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
           catch
            {
                return 0;
            }
          
        }
        public KH getKH(string id)
        {
            KH kh = new KH();
            try
            {
                string sql = "select * from KHACHHANG where ID ='" + id + "'";
                DataTable dt = DatabaseConnect.ExecuteQuery(sql);
                kh.id = dt.Rows[0]["ID"].ToString();
                kh.sotien = Int32.Parse(dt.Rows[0]["SOTIEN"].ToString());
                kh.matkhau = dt.Rows[0]["MATKHAU"].ToString();
                kh.ten = dt.Rows[0]["TEN"].ToString();
                return kh;
            }
            catch
            {
                return kh;
            }
            
        }

        public int rutTien(string id, int sotien)
        {
            try
            {
                string sql = "UPDATE KHACHHANG SET SoTien = " + sotien.ToString() + "WHERE ID ='" + id + "'";
                int i = DatabaseConnect.ExecuteNoneQuery(sql);
                return 1;
            }
            catch
            {
                return 0;

            } 

        }

        public int kiemTraTaiKhoan(string id)
        {
            try
            {
                string sql = "select * from KHACHHANG where ID ='" + id + "'";
                DataTable dt = DatabaseConnect.ExecuteQuery(sql);
                DataRow dr = dt.Rows[0];
                return 1;
            }
            catch
            {
                return 0;
            }
        }
    }
}
